package cn.com.eado.crm.app.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/** PackageUtil
 * Created by Administrator on 2017/12/2.
 */

public class PackageUtil {
    public static int getVersionCode(Context context){
        int versionCode = 0;
        PackageManager pm = context.getPackageManager();
        try {
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionCode = pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
//            LogUtil.e.e("PackageInfo", "Exception");
        }
        return versionCode;
    }

    public static String getVersionName(Context context){
        String versionName = "";
        PackageManager pm = context.getPackageManager();
        try {
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
            if (versionName.isEmpty() || versionName.length()<=0){
                return "";
            }
        } catch (PackageManager.NameNotFoundException e) {
//            LogUtil.e.e("PackageInfo", "Exception");
        }
        return versionName;
    }
}
